package com.qzsoft.zhjd.server.modules.ludong.asphalt.controller;

import com.qzsoft.zhjd.server.common.utils.MapToBeanUtils;
import com.qzsoft.zhjd.server.common.utils.R;
import com.qzsoft.zhjd.server.modules.ludong.asphalt.entity.AsphaltConcreteBondEntity;
import com.qzsoft.zhjd.server.modules.ludong.asphalt.service.AsphaltConcreteBondService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;


/**
 *
 *功能描述:沥青混凝土筛孔通过率阈值（上下限）表
 * @author jiangyafei
 * @email jiangyf_sd@163.com
 * @date 2020-06-09 11:17:43
 */
@Slf4j
@RestController
@RequestMapping("datacollect/asphalt/asphaltconcretebond")
public class AsphaltConcreteBondController {
    @Autowired
    private AsphaltConcreteBondService asphaltConcreteBondService;

    /**
     * 保存
     */
    @PostMapping("/save")
    public R save(@RequestParam Map<String,Object> params){
        log.info("沥青混凝土筛孔通过率阈值（上下限）表==="+params.toString());
        if(params != null && params.size()>0 ){
            Map<String,Object> map = MapToBeanUtils.toReplaceKeyLow(params);
            try{
                AsphaltConcreteBondEntity asphaltConcreteBondEntity = MapToBeanUtils.mapToObject(map,AsphaltConcreteBondEntity.class);
                if(StringUtils.isNotBlank(asphaltConcreteBondEntity.getId())){
                    asphaltConcreteBondService.removeById(asphaltConcreteBondEntity.getId());
                    asphaltConcreteBondService.save(asphaltConcreteBondEntity);
                    return R.ok();
                }
            }catch (Exception e){
                log.error(e.getMessage());
                return R.error(400,e.getMessage());
            }
        }
        return R.error(400,"数据为空");
    }


}
